<%--
  Created by IntelliJ IDEA.
  User: Edward_yang
  Date: 2017/12/20 0020
  Time: 23:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>产品列表</title>
    <script type="text/javascript">
        function formatterImg(value){
            if(value!=null){
                return '<img height="30px" src="'+value+'" alt="" />';
            }else{
                return '';
            }
        }
        //初始化分类数据 标签数据 城市数据
        $(function(){
            //分类
            $('#categoryId ').combotree({
                url : '${path }/category/allTree.do?root=1',
                parentField : 'pid',
                lines : true,
                panelHeight : 'auto'
            });
            //城市
            $('#areaId').combotree({
                url : '${path }/areaInfo/allTree.do?root=1',
                parentField : 'pid',
                lines : true,
                panelHeight : 'auto'
            });
            //标签
            $('#labelDetailCodeTree').combotree({
                url : '${path }/label/allTree.do?sellerId=-1&root=-1',
                parentField : 'pid',
                lines : true,
                panelHeight : 'auto',
                onSelect: function(node) {
                    if (!$(this).tree('isLeaf', node.target)) {
                        alert("必须选择叶子节点");
                        //清除选中
                        $('#labelDetailCodeTree').combotree('clear');
                        return false;
                    }
                    $("#labelDetailCode").val(node.attributes);
                }
            });
        });
    </script>
    <style>
        .color_001{
            color:#093;
        }
        .color_002{
            color: #f93;
        }
        .color_003{
            color: #f30;
        }

    </style>
</head>
<script>
    var IsCheckFlag = true; //标示是否是勾选复选框选中行的，true - 是 , false - 否
    $(function () {
        $("#product_tt").datagrid({//数据表格
            url:"${path}/product/productList.do",
            width:"100%",
            height:"775px",
            fitColumns: true,//宽度自适应
            align:"center",
            loadMsg:"正在处理，请等待......",
            striped: true,//true是否把一行条文化
            idField:"id",//唯一性标示字段
            pagination:true,//显示分页栏
            rownumbers:true,//显示行号
            singleSelect:true,//true只可以选中一行
            pageSize:20,
            frozenColumns:[[//冻结字段
                {field:"ck",checkbox:true}
            ]],
            onClickCell: function (rowIndex, field, value) {
                IsCheckFlag = false;
            },
            onSelect: function (rowIndex, rowData) {
                if (!IsCheckFlag) {
                    IsCheckFlag = true;
                    $("#product_tt").datagrid("unselectRow", rowIndex);
                }
            },
            onUnselect: function (rowIndex, rowData) {
                if (!IsCheckFlag) {
                    IsCheckFlag = true;
                    $("#product_tt").datagrid("selectRow", rowIndex);
                }
            },
            columns:[[//未冻结字段
                {field:"productName",title:"套餐名称",width:80},
                {field:"productImg",title:"套餐图片",width:60,formatter:formatterImg},
                {field:"sellerName",title:"商家名称",width:60},
                {field:"originPrice",title:"产品原价(元)",width:40},
                {field:"price",title:"产品现价(元)",width:40},
                {field:"repertory",title:"库存",width:40},
                {field:"verifyType",title:"审核状态",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font class='color_002'>待审核</font>";
                        }else if(value=="1"){
                            return "<font class='color_001'>上架</font>";
                        }else if(value=="2"){
                            return "<font class='color_003'>下架</font>";
                        }
                    }
                },
                {field:"status",title:"状态",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font class='color_003'>禁用</font>";
                        }else if(value=="1") {
                            return "<font class='color_001'>正常</font>";
                        }
                    }
                },
                {field:"type",title:"产品类型",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font>体检套餐</font>";
                        }else if(value=="1") {
                            return "<font >线上体检卡</font>";
                        }else if(value=="2") {
                            return "<font >线下体检卡</font>";
                        }else if(value=="3") {
                            return "<font >邮寄产品</font>";
                        }
                    }
                },
                {field:"virtaulCommentCount",title:"虚拟评论数量",width:40},
                {field:"virtualAppointmentCount",title:"虚拟预约数量",width:40},
                {field:"virtualCollectAccount",title:"虚拟收藏数量",width:40},
                {field:"virtualSalesCount",title:"虚拟销售数量",width:40},
                {field:"salesCount",title:"销售数量",width:40},
                {field:"commentCount",title:"评论数量",width:30},
                {field:"commentScore",title:"评分",width:20},
                {field:"appointmentCount",title:"预约数量",width:30},
                {field:"collectAccount",title:"收藏数量",width:30},
                {field:"createDate",title:"创建时间",width:80,formatter: formatDatebox}
            ]],
            toolbar:[
                <shiro:hasPermission name="/product/add.do">
                "-",
                {//工具条
                    text:"添加",
                    iconCls:"icon-add",
                    handler:function(){
                        var msg="添加";
                        $.modalDialog({
                            title : msg+'产品',
                            id:'modelAdd',
                            width : 1000,
                            height : 600,
                            href : '${path }/product/gotoAddProudct.do'

                        });

                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/product/edit.do">
                {//工具条
                    text:"修改",
                    iconCls:"icon-edit",
                    handler:function(){
                        var rowsData = $("#product_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作产品',"info");
                        }else{
                            var msg="修改";
                            $.modalDialog({
                                title : msg+'产品',
                                id:'modelEdit',
                                width : 1000,
                                height : 600,
                                href : '${path }/product/gotoEditProudct.do?productId='+rowsData[0].id
                            });
                        }

                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/product/delete.do">
                {
                    text:"删除",
                    iconCls:"icon-remove",
                    handler:function(){
                        var rowsData = $("#product_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作产品',"info");

                        }else{
                            if(rowsData[0].status!=0){
                                var msg="正常状态"
                                $.messager.alert('系统提示','该产品属于'+msg,"info");
                                return;
                            }else{
                                deleteProduct(rowsData);
                            }


                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/product/checkProduct.do">
                {//工具条
                    text:"审核",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#product_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作产品',"info");
                        }else{
                            $.modalDialog({
                                title : '审核产品',
                                id:'modelCheckProduct',
                                width : 300,
                                height : 150,
                                href : '${path }/product/gotoCheckProduct.do?productId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/product/checkStauteProduct.do">
                {//工具条
                    text:"启用|禁用",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#product_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作产品',"info");
                        }else{
                            $.modalDialog({
                                title : '启用|禁用',
                                id:'modelCheckStauteProduct',
                                width : 300,
                                height : 150,
                                href : '${path }/product/gotoCheckStauteProduct.do?productId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/product/editProductServeLabel.do">
                {//工具条
                    text:"编辑服务标签",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#product_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作产品',"info");
                        }else{
                            $.modalDialog({
                                title : '编辑服务标签',
                                id:'editProductServeLabel',
                                width : 400,
                                height : 300,
                                href : '${path }/product/gotoeditProductServeLabel.do?productId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                {text:"刷新",
                    iconCls:"icon-reload",
                    handler:function(){
                        $("#product_tt").datagrid("clearSelections");//删除后取消所有选项
                        $("#product_tt").datagrid("reload");
                    }
                },"-",
            ]
        });
        //扩展的Date的format方法(上述插件实现) 日期转换格式
        Date.prototype.format = function (format) {
            var o = {
                "M+": this.getMonth() + 1, // month
                "d+": this.getDate(), // day
                "h+": this.getHours(), // hour
                "m+": this.getMinutes(), // minute
                "s+": this.getSeconds(), // second
                "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
                "S": this.getMilliseconds()
                // millisecond
            }
            if (/(y+)/.test(format))
                format = format.replace(RegExp.$1, (this.getFullYear() + "")
                    .substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }
        //调用日期转化格式方法
        function formatDatebox(value) {

            if (value == null || value == '') {
                return '';
            }
            var dt;
            if (value instanceof Date) {
                dt = value;
            } else {
                dt = new Date(value);
            }

            return dt.format("yyyy-MM-dd hh:mm:ss");
        }

    });
    function reloadpProductDataGrid() {
        $('#product_tt').datagrid('reload');
    }
    //关闭窗口
    function closeWin(str) {
        $('#'+str).dialog("close");
    }

    //删除
    function deleteProduct(rowsData) {
        $.messager.confirm("系统提示", "<p class='tipInfo'>你确定要删除吗?</p>",function(data){
            $.messager.progress();
            if(data){//判断是否删除
                if (rowsData){//判断是否找到当前行，找到后异步形式从数据库中删除当前记录
                    var productId=rowsData[0].id;
                    $.ajax({
                        type: "POST",
                        dataType: "JSON",
                        url: "${path}/product/delete.do",
                        data: {"productId":productId},
                        success: function(data){
                            $.messager.progress("close");
                            if(data.success){
                                $.messager.show({
                                    title:"系统提示",
                                    msg:"删除成功!",
                                    timeout:600,
                                    style:"left:30%;top:10%",
                                    showType:"fade"
                                });
                                $("#product_tt").datagrid("clearSelections");//删除后取消所有选项
                                $("#product_tt").datagrid("reload");
                            }else{
                                $.messager.progress("close");
                                $.messager.alert("系统提示", data.msg,"error");
                            }
                        },
                        error:function(){
                            $.messager.progress("close");
                            $.messager.alert("系统提示", "服务器连接失败!","error");
                        }
                    });
                }
            }
        });
    }

    //重置
    function reset() {
        $("#sellerName").val("");
        $("#productName").val("");
        $("#productVerifyType").val("-1");
        $("#productStatus").val("-1");
        $("#productCity").val("-1");
        $('#categoryId').combobox('setValue', '--请选择--');
        $("#labelId").val("-1");
        $("#productAttr").val("-1");
        window.location.href="${path}/product/gotoProductInfo.do"
        $('#product_tt').datagrid('reload');
    }
    //查询
    function queryingProduct(){

        var queryParams = {
            sellerName:$("#sellerName").val(),
            productName:$("#productName").val(),
            verifyType:$("#productVerifyType").val(),
            status:$("#productStatus").val(),
            cityid:$("#areaId").combotree("getValue"),
            classifyid:$("#categoryId").combotree("getValue"),
            labelCode:$("#labelDetailCode").val(),
        }
        var options = $("#product_tt").datagrid('getPager').data("pagination").options;
        options.pageNumber = 1;
        //重新加载
        $("#product_tt").datagrid('options').url = "${path}/product/productList.do";
        $("#product_tt").datagrid('options').queryParams = queryParams;
        $("#product_tt").datagrid('reload');
    }

</script>
<body style="padding:0px" >
<h2 style="margin-bottom: 0px">产品列表</h2>
<div style="border:3px solid rgb(95,158,160)">
</div>
    <div class="main" style="width: 100%;">
        <style type="text/css">
            .searchTab{font:12px arial,helvetica,sans-serif;border:2px solid rgb(95,158,160)}
            .searchTab td{font:100% arial,helvetica,sans-serif;height:30px;padding:5px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
            .searchTab{width:100%;border-collapse:collapse}
            .searchTab td{border:0px solid #e0e0e0;padding-left:5px;text-align: right}
        </style>
        <table class="searchTab">
            <tr>
                <td class="search_toright_td"  style="width:60px;">商家名称：</td>
                <td class="search_toleft_td" style="width:80px;"><input type="text" style="width:90px;" id="sellerName" name="sellerzh" class="searchTabinput"/></td>
                <td class="search_toright_td" style="width:60px;">产品名称：</td>
                <td class="search_toleft_td" style="width:80px;"><input type="text" style="width:90px;" id="productName" name="productName" class="searchTabinput"/></td>
                <td class="search_toright_td" style="width:60px;">审核状态：</td>
                <td class="search_toleft_td" style="width:80px;">
                    <select id="productVerifyType" style="width:80px;" class="querySelect">
                        <option value="-1">--请选择--</option>
                        <option value="0">待审核</option>
                        <option value="1">上架</option>
                        <option value="2">下架</option>
                    </select>
                <td class="search_toright_td" style="width:60px;">状态：</td>
                <td class="search_toleft_td" style="width:80px;">
                    <select id="productStatus" style="width:80px;" class="querySelect">
                        <option value="-1">--请选择--</option>
                        <option value="0">禁用</option>
                        <option value="1">正常</option>
                    </select>
                </td>
                <td class="search_toright_td" style="width:60px;">城市：</td>
                <td class="search_toleft_td" style="width:80px;">
                    <select id="areaId" name="areaId" style="width:150px;"></select>
                </td>
                <td class="search_toright_td" style="width:60px;">分类：</td>
                <td class="search_toleft_td" style="width:80px;">
                    <select id="categoryId" name="categoryId" style="width:150px;"></select>
                </td>
                <td class="search_toright_td" style="width:60px;">标签：</td>
                <td class="search_toleft_td" style="width:80px;">
                    <select id="labelDetailCodeTree" name="labelDetailCodeTree" style="width:150px;"></select>
                    <input id="labelDetailCode" name="labelDetailCode" type="hidden">
                </td>
                <td class="search_toleft_td">&nbsp;&nbsp;
                    <a id="btnCancel" class="easyui-linkbutton" icon="icon-search" href="javascript:queryingProduct()">查询</a>
                    <a id="btnCance2" class="easyui-linkbutton"  iconCls="icon-undo" href="javascript:reset()">重置</a>
                </td>
            </tr>
        </table>
    </div>

    <table id="product_tt" style="border: 1px solid rgb(95,158,160);white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
    </table>
</body>
</html>
